package com.cy.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@interface Entity{
    String value() default "";
}

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD,ElementType.METHOD})
@interface ID{
    String value() default "";
}

@Entity("t_user")
class User{
    @ID("uid")
    private Integer id;
}

public class AnnotationTests {
    public static void main(String[] args) throws NoSuchFieldException {
        //1 获取user类上的entity注解的内容
        //1.1 获取 user的字节码对象
        Class<?> targetCls=User.class;
        String entityValue = User.class.getAnnotation(Entity.class).value();
        System.out.println(entityValue);


        //2获取id属性上注解的ID属性值
        //
        Field f =targetCls.getDeclaredField("id");
        ID id =f.getAnnotation(ID.class);
        String f2=id.value();
        System.out.println(f2);

    }
}